package com.cs.cssupplier.controller;

import com.cs.cssupplier.domain.CsFinancialStatus;
import com.cs.cssupplier.domain.CsPersonnel;
import com.cs.cssupplier.mapper.CsWinningResultsMapper;
import com.cs.cssupplier.service.CsFinancialStatusService;
import com.cs.cssupplier.service.CsPersonnelService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author：lyj
 * @Package：com.cs.cssupplier.controller
 * @Project：RuoYi-Cloud-master
 * @name：CsPersonnelController
 * @Date：2024/11/14 17:36
 * @Filename：CsPersonnelController
 */
@RestController
@RequestMapping("/personnel")
public class CsPersonnelController extends BaseController {
    @Resource
    private CsPersonnelService csPersonnelService;
    @Autowired
    private CsWinningResultsMapper mapper;

    /**
     * 根据id查询技术人员
     * @param js_id
     * @return
     */
    @GetMapping(value = "/{js_id}")
    public AjaxResult EnterpriseId(@PathVariable("js_id")Long js_id){
        return AjaxResult.success(csPersonnelService.selectPersonneljsId(js_id));
    }

    /**
     * 查询所有的技术人员信息
     * @param csPersonnel
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(CsPersonnel csPersonnel){
        startPage();
        List<CsPersonnel> list=csPersonnelService.selectPersonnelList(csPersonnel);
        return getDataTable(list);
    }

    /**
     * 添加技术人员信息
     * @param csPersonnel
     * @return
     */
    @PostMapping
    public AjaxResult insertFinancialStatus(@RequestBody CsPersonnel csPersonnel){
        return toAjax(csPersonnelService.addPersonnelStatus(csPersonnel));
    }

    /**
     * 修改技术人员信息
     * @param csPersonnel
     * @return
     */
    @PutMapping
    public AjaxResult updateEnterprise(@RequestBody CsPersonnel csPersonnel){
        Long userid = SecurityUtils.getLoginUser().getUserid();
        Long sipplierByUserId = mapper.getSipplierByUserId(userid);//这才是供应商id
        System.out.println(sipplierByUserId+"dsdsdsssssssssssssssssssssssss");
        csPersonnel.setHid(sipplierByUserId);
        System.out.println(csPersonnel);
        System.out.println(csPersonnelService.updatePersonnel(csPersonnel)+"dsad");
        return toAjax(csPersonnelService.updatePersonnel(csPersonnel));
    }

    /**
     * 批量删除技术人员
     * @param js_id
     * @return
     */
    @DeleteMapping("/{js_id}")
    public AjaxResult deleteEnterprise(@PathVariable Long [] js_id){
        return toAjax(csPersonnelService.deleteListPersonnel(js_id));
    }
}
